package com.itheima.demo02.FileUpload;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer {
    public static void main(String[] args) throws IOException {
        //java创建服务器,端口号为8888
        ServerSocket server = new ServerSocket(8888);
        //获取客户端socket
        Socket socket = server.accept();
        //获取网络输入流
        InputStream is = socket.getInputStream();
        File file = new File("day11_Net\\upload");
        if (!file.exists()) {
            file.mkdirs();
        }
        FileOutputStream fos = new FileOutputStream(file + "\\1.jpg");
        int len = 0;
        byte[] bytes = new byte[1024];
        while ((len = is.read(bytes)) != -1) {
            fos.write(bytes, 0, len);
        }
        OutputStream os = socket.getOutputStream();
        os.write("上传成功!".getBytes());
        fos.close();
        socket.close();
    }
}
